export default class player extends Laya.Script {
    // 更多参数说明请访问: https://ldc2.layabox.com/doc/?nav=zh-as-2-4-0
    owner=this.owner as Laya.Sprite
    rig=null;
    timeLine=null;
    chaX=null;
    constructor() { super(); }
    onAwake(){
        
       
        this.rig=this.owner.getComponent(Laya.RigidBody)
        Laya.stage.on(Laya.Event.MOUSE_DOWN,this,function(){ 
            this.chaX=Laya.stage.mouseX-this.owner.x
            Laya.Tween.to(this.owner,{x:Laya.stage.mouseX,y:Laya.stage.mouseY},1500,null,null,null,false);
            if(this.chaX<0){
                this.owner.autoAnimation="zuo"
            }else{
            this.owner.autoAnimation="you"
            }
        })
    }
    onTriggerEnter(other){
        if(other.label=="food"){
            this.owner.autoAnimation="chi"
        }
        if(other.label=="AI"){
            var timeLine=Laya.TimeLine.to(this.owner,{rotation:180},100,Laya.Ease.backOut)
            .to(this.owner,{rotation:0},150,null,100);
            timeLine.play(0,false);
            Laya.SoundManager.playSound("res/sound/player.wav",1);
        }
    }
    
}